#include "StdAfx.h"
#include "globals.h"

struct MessageType
{
    enum Enum
    {
        Error,
        Warning,
        Information,
        Question,
    };
};

static void showMessageBox( MessageType::Enum messageType, const QString & titleStr, const QString & text, bool & result )
{
    result = false;
    QMessageBox * messageBox = NULL;
    switch ((MessageType::Enum) messageType)
    {
    case MessageType::Error:
        messageBox = new QMessageBox( QMessageBox::Critical, titleStr, text, QMessageBox::Ok );
        break;

    case MessageType::Warning:
        messageBox = new QMessageBox( QMessageBox::Warning, titleStr, text, QMessageBox::Ok );
        break;

    case MessageType::Information:
        messageBox = new QMessageBox( QMessageBox::Information, titleStr, text, QMessageBox::Ok );
        break;

    case MessageType::Question:
        messageBox = new QMessageBox( QMessageBox::Question, titleStr, text, QMessageBox::Ok | QMessageBox::Cancel );
        break;

    default:
        assert( 0 );
        return;
    }

    result = ( messageBox->exec() == QMessageBox::Ok ) ? true : false;
    delete messageBox;
}

void errorBox( const QString & errorStr )
{
    bool dummyResult = false;
    showMessageBox( MessageType::Error, QObject::tr( "Error" ), errorStr, dummyResult );
}

void warningBox( const QString & warningStr )
{
    bool dummyResult = false;
    showMessageBox( MessageType::Warning, QObject::tr( "Warning" ), warningStr, dummyResult );
}

void informationBox( const QString & informationStr )
{
    bool dummyResult = false;
    showMessageBox( MessageType::Information, QObject::tr( "Information" ), informationStr, dummyResult );
}

bool questionBox( const QString & titleStr, const QString & questionStr )
{
    bool result = false;
    showMessageBox( MessageType::Question, titleStr, questionStr, result );
    return result;
}